package com.example.thymeleaftest.controller;

import java.io.FileInputStream;
import java.io.InputStream;
import java.security.MessageDigest;

public class testSha {
        public static void main(String[] args) throws Exception {
            // 打开文档并读取内容
            InputStream fis = new FileInputStream("C:\\Users\\cha'r'm\\Desktop\\k5部署\\03-148楼\\验收文档.zip");
            byte[] buffer = new byte[1024];
            MessageDigest md = MessageDigest.getInstance("SHA-1");

            // 计算SHA-1哈希值
            int numRead;
            do {
                numRead = fis.read(buffer);
                if (numRead > 0) {
                    md.update(buffer, 0, numRead);
                }
            } while (numRead != -1);

            fis.close();

            byte[] hash = md.digest();

            // 将哈希值输出为十六进制字符串
            StringBuilder hexString = new StringBuilder();
            for (byte b : hash) {
                String hex = Integer.toHexString(0xff & b);
                if (hex.length() == 1) hexString.append('0');
                hexString.append(hex);
            }
            System.out.println(hexString.toString());
        }


}
